package field;

import java.util.ResourceBundle;

import player.Player;
import adapter.Adapter;

public class FieldController {

	private int[][] fieldPrice, fieldRent;
	private Field[] fields;
	private String[] title, desc, subtitle, luckText;
	private int[] rent,prices,shipRent;
	private Adapter adapter;
	private LuckController luckC = new LuckController();

	/**
	 * Giver fieldcontroller en specifik adapter (der kan indeholde GUIFields)
	 * @param adapter Adapter objekt indeholdende GUIFields
	 */
	public void setAdapter(Adapter adapter){
		this.adapter = adapter;
	}

	public Field[] getFields(){
		return fields;
	}

	/**
	 * Udfører konsekvens af at lande på et felt
	 * @param field Feltnummeret der landes på (i arrayet: 0-39)
	 * @param player Spilleren der lander på feltet
	 * @return SpillerData der skal håndteres/opdateres
	 */
	public int[] landOnField(int field, Player player, int dicesum){
		int[] cnsq = new int[3];
		cnsq[1] = field;
		adapter.setCenter(field); // Viser GUI-feltets beskrivelse på spillepladen

		if (fields[field] instanceof Shipping){
			cnsq[0] = landOnShipping(field, player);
		}
		else if (fields[field] instanceof Brewery){
			cnsq[0] = landOnBrewery(field, player, dicesum);
		}
		else if (fields[field] instanceof Property){
			cnsq[0] = landOnProperty(field, player);
		}
		else if (fields[field] instanceof Tax){
			cnsq[0] = landOnTax(field, player);
		}
		else if (fields[field] instanceof Refuge){
			cnsq = landOnRefuge(field, player);
		}
		else if (fields[field] instanceof Luck){
			cnsq = landOnLuck(field, player);
		}
		return cnsq;
	}

	/**
	 * Hvis feltet er af typen Shipping
	 * @param field Feltet der er landet pås plads i arrayet (0-39)
	 * @param player Spilleren der er landet på feltet
	 * @return Hvor meget spillerens saldo skal påvirkes
	 */
	private int landOnShipping(int field, Player player){
		Player owner = ((Ownable) fields[field]).getOwner(); 
		int ships = 0;
		int output = 0;
		int n=0;
		if (((Ownable) fields[field]).getOwner() != null && player != ((Ownable) fields[field]).getOwner() && ((Ownable) fields[field]).getPawned() == false ){
			while (n<40){
				if (fields[n] instanceof Shipping){
					if (((Ownable) fields[n]).getOwner() == owner){
						ships++;
					}
				}
				n++;
			}
			updateOwner(owner, -((Shipping) fields[field]).getShipRent(ships));
			output = -((Shipping) fields[field]).getShipRent(ships);
		}
		else if (owner == null){ // Hvis feltet ikke ejes af nogen
			output = buyField(player, field);
		}
		else if (owner == player){
			output = 0;
		}
		return output;
	}

	/**
	 * Hvis feltet er af typen Refuge
	 * @param field: Feltet der er landet på
	 * @param player: Spilleren der er landet på feltet
	 * @return int[], der returnerer hvad der sker med spillerens balance, hvilken position og spillerens-fængselssituation
	 */
	private int[] landOnRefuge(int field, Player player){
		ResourceBundle msg = adapter.getBundle();
		int[] output = {0,player.getPosition(),0};
		if (fields[field].getFieldNumber() == 31){ //Tjekker om feltet man er landet på er "gå til fængsel"
			for (int i=0; i<fields.length; i++){ //Hvis gameboard=shufflet, så findes spillerens korrekte position
				if (fields[i].getFieldNumber() == 31){
					output[1] = i;
				}
			}
			adapter.showMessage(player.getName() + " : " + msg.getString("Jailed"));
			adapter.removeCar(output[1]+1, player.getName());
			adapter.setCar(moveToJail()+1, player.getName());
			output[1] = moveToJail();
			output[2] = 1;
			return output;
		}
		return output;
	}

	/**
	 * Finder feltet Jail i tilfælde af gameboard er shufflet
	 * @return Feltets nummer i arrayet
	 */
	public int moveToJail(){
		int output=0;
		for (int i=0; i<fields.length; i++){ //Hvis gameboard=shufflet, så findes spillerens korrekte position
			if (fields[i].getFieldNumber() == 11){
				output = i;
			}
		}
		return output;
	}

	/**
	 * 
	 * @param field: Feltet der er landet på
	 * @param player: Spilleren der er landet på feltet
	 * @param diceSum: Terningesummen - Bruges til Brewery's rent
	 * @return Hvor meget spillerens balance påvirkes
	 */
	private int landOnBrewery (int field, Player player, int diceSum){
		int output = 0;
		Player owner = ((Ownable) fields[field]).getOwner();
		int brewery = 0;
		int n=0;

		if (owner != player && ((Ownable) fields[field]).getPawned() == false){
			if (owner == null){
				output=buyField(player, field);
			}
			else{
				while (n<40){
					if (fields[n] instanceof Brewery){
						if (((Ownable) fields[n]).getOwner() == owner){
							brewery++;
						}
					}
					n++;
				}
				if (brewery == 1){
					output = -100*diceSum;
				}
				if (brewery == 2){
					output = -100*diceSum*2;
				}
				updateOwner(owner, output);
			}
		}
		return output; 
	}

	/**
	 * Hvis feltet er af typen Luck
	 * @param field: Feltet der er landet på
	 * @param player: Spilleren der er landet på feltet
	 * @return Return for Luck: Beløb, og om spilleren skal rykke
	 */
	private int[] landOnLuck(int field, Player player){
		int[] output = luckC.getLucky((Luck) fields[field]);
		if (output[1]>0){
			int pos = player.getPosition()+1;
			adapter.removeCar(pos, player.getName());
			if(player.getPosition()+output[1] >= 40 ){
				output[1] = output[1]-((40) - player.getPosition());
				output[0] = output[0] + 4000; // Man får 4000 for at passere Start
			}
			else{
				output[1] = output[1] + player.getPosition(); 
			}
			adapter.setCar(output[1]+1, player.getName());
			return output;
		}
		else{
			output[1]=player.getPosition();
			return output;	
		}
	}

	/**
	 * Land på et Tax felt
	 * @param field Feltets nummer i arrayet
	 * @param player Spilleren der er landet på feltet
	 * @return Prisen der skal betales af spilleren
	 */
	private int landOnTax(int field, Player player){
		int taxcnsq = -((Tax) fields[field]).getTax();
		if (taxcnsq == -2000) { 
			return taxcnsq;
		} else {
			boolean choice = adapter.getUserTaxChoice(Integer.toString(-taxcnsq), player.getName());
			if (choice == true){
				int value = player.getAccount().getBalance();		
				for (int i = 0; i < fields.length; i++) {
					if (fields[i] instanceof Ownable){
						Player owner = ((Ownable) fields[i]).getOwner();

						if (owner == player){
							value = value + ((Ownable) fields[i]).getPawnPrice();

							if (fields[i] instanceof Property){
								value = value + ((Property) fields[i]).getBuyBuildingPrice() * ((Property) fields[i]).getHouseCount();
							}
						}
					}
				}
				return -(int) (value*0.1); // Spilleren betaler 10% af sin samlede værdi
			}
			else { // Spilleren har valgt at betale fast beløb - 4000
				return taxcnsq;
			}
		}
	}

	/**
	 * Tjekker om Property-feltet ejes eller ej, og returnerer med enten leje for feltet eller buyField()
	 * @param field
	 * @param player
	 * @return
	 */
	private int landOnProperty(int field, Player player){
		Player owner = ((Ownable) fields[field]).getOwner();
		int output = 0;
		int[] maxBloks = new int[]{4, 2, 3, 3, 3, 3, 3, 3, 2}; 

		if (owner == null) {
			output=buyField(player, field);
		} else if (owner != player && ((Ownable) fields[field]).getPawned() == false){
			output=-((Ownable) fields[field]).getRent();
			int p = 0;
			for (int n=0; n<fields.length;n++){
				if (fields[n] instanceof Property){
					//Tjekker hvor mange grunde ejeren af feltet ejer i den blok
					if (((Property) fields[n]).getBlock() == ((Property) fields[field]).getBlock() && ((Property) fields[n]).getOwner() == owner){
						p++;
					}
				}
			}
			//Hvis ejeren af feltet ejer samtlige felter i blokken og der ikke er huse på skal der betales dobbelt leje
			if (p == maxBloks[((Property) fields[field]).getBlock()] && ((Property) fields[field]).getHouseCount() == 0){
				output = output * 2;
			}
			updateOwner(owner, output);			
		}
		return output;
	}

	/**
	 * Opdaterer ejerens balance
	 * @param owner Ejeren af et felt
	 * @param amt Beløbet der skal opdateres med
	 */
	private void updateOwner(Player owner, int amt){
		owner.getAccount().setBalance(owner.getAccount().getBalance() - amt);
		adapter.setBalance(owner.getName(), owner.getAccount().getBalance());
	}

	/**
	 * Opdaterer samtlige felter på GUI'en så den reflekterer spillets data
	 */
	private void updGuiFields(){
		int[] maxBloks = new int[]{4, 2, 3, 3, 3, 3, 3, 3, 2};
		int rent = 0;
		for (int n=0; n<fields.length;n++){
			if (fields[n] instanceof Ownable){
				rent = ((Ownable) fields[n]).getRent();
				Player owner = ((Ownable) fields[n]).getOwner();
				if (owner != null){
					int p = 0;
					if (fields[n] instanceof Property){	
						for (int i=0; i<fields.length;i++){
							if (fields[i] instanceof Property){
								//Tjekker hvor mange grunde ejeren af feltet ejer i den blok
								if (((Property) fields[i]).getBlock() == ((Property) fields[n]).getBlock() && ((Property) fields[i]).getOwner() == owner){
									p++;
								}
							}
						}
						if (p == maxBloks[((Property) fields[n]).getBlock()] && ((Property) fields[n]).getHouseCount() == 0){
							rent = rent * 2;
						}
						adapter.setOwner(n, owner.getName());
						adapter.setSubTextProperty(n, Integer.toString(rent));
					}
					else if (fields[n] instanceof Brewery){
						for (int i=0; i<fields.length;i++){
							if (fields[i] instanceof Brewery){
								//Tjekker hvor mange grunde ejeren af feltet ejer i den blok
								if (((Brewery) fields[i]).getOwner() == owner){
									p++;
								}
							}
						}
						if (p == 2){
							rent = rent * 2;
						}
						adapter.setOwner(n, owner.getName());
						adapter.setSubTextBrewery(n, Integer.toString(rent));
					}
					else if (fields[n] instanceof Shipping){
						int ships = 0;
						for (int i = 0; i < fields.length; i++) {
							if (fields[i] instanceof Shipping){
								if (((Shipping) fields[i]).getOwner() == owner){
									ships++;
								}
							}
						}
						adapter.setOwner(n, owner.getName());
						adapter.setSubText(n, Integer.toString(((Shipping) fields[n]).getShipRent(ships)));
					}
					if (((Ownable) fields[n]).getPawned() == true){
						adapter.pawn(n);
					}
				}
				else if (owner == null){
					adapter.setSubText(n, fields[n].getSubtitle() + ((Ownable) fields[n]).getPrice());
				}
			}
		}
	}

	/**
	 * Hvis en spiller gerne vil købe en ejendom
	 * @param player: Spilleren der vil købe feltet
	 * @param field: Feltet spilleren gerne vil købe
	 * @return Opdaterer spillerens balance
	 */
	private int buyField(Player player, int fieldNmb){
		int output = 0;
		Ownable field = ((Ownable) fields[fieldNmb]);
		if (player.getAccount().getBalance() >= field.getPrice()){
			boolean choice = adapter.buyField(player.getName());
			if (choice == true){
				field.setOwner(player);
				updGuiFields(); // Opdaterer samtlige felter på GUI'en
				output = -field.getPrice();
			}
			else if (choice == false){// Der sker intet hvis spilleren ikke ønsker at købe det
			}
		}
		else  {
			//Der sker intet hvisspilleren ikke har råd til at købe feltet.
		}
		return output;
	}

	/**
	 * Tilføjer huse på GUI 
	 * @param field
	 */
	public int buyHouse(int field){

		int houseCount = ((Property) fields[field]).getHouseCount();
		if (houseCount < 5){

			if (houseCount < 4 && houseCount >= 0){ //Hvis der er mellem 0 og fire huse, tilføjes ét hus
				houseCount++;
				((Property) fields[field]).setHouseCount(houseCount);
				adapter.setHouses(field,houseCount);
			}
			else if (houseCount==4){ //hvis der er 4 huse, tilføjes hotel. (og huse fjernes)
				houseCount++;
				((Property) fields[field]).setHouseCount(houseCount);
				adapter.setHotels(field, true);
			}
		}
		updGuiFields();
		//Pris for hus opkræves 
		return -((Property) fields[field]).getBuyBuildingPrice();
	}

	/**
	 * Fjerner huse på GUI 
	 * @param field
	 */
	public int sellHouse(int field){
		int houseCount = ((Property) fields[field]).getHouseCount();
		if (houseCount>0) {
			if (houseCount==5){	      //Hvis der er hotel, fjernes hotel og der sættes fire huse 
				adapter.setHotels(field, false);
				houseCount--;
				((Property) fields[field]).setHouseCount(houseCount);
				adapter.setHouses(field, houseCount);
			}
			if (houseCount<=4){ //Hvis der er fire el. under huse, fjernes ét hus. 
				houseCount--;
				((Property) fields[field]).setHouseCount(houseCount);
				adapter.setHouses(field, houseCount);
			}
		}
		updGuiFields();
		//Sælger skal have halvdelen af husprisen. 
		return (((Property) fields[field]).getBuyBuildingPrice())/2;
	}

	/**
	 * Ophæver pantsættelsen
	 * @param field: feltet der landes på
	 * @return Returnerer int, der indeholder prisen+10% for ophævelsen af pænsættelsen.
	 */
	public int unPawn(int field){
		((Ownable) fields[field]).setPawned(false);
		updGuiFields();
		return -(int) (((Ownable) fields[field]).getPawnPrice()*1.1);
	}

	/**
	 * Pantsætter en grund
	 * @param fieldnmb Feltet der landes pås nummer i arrayet
	 * @return Beløbet spillerens konto skal påvirkes med
	 */
	public int pawn(int field){
		((Ownable) fields[field]).setPawned(true);
		adapter.pawn(field);
		return ((Ownable) fields[field]).getPawnPrice();
	}
	
	/**
	 * Nulstiller ownable felter på GUI'en til deres oprindelige status (Beskrivelse + pris) når en spiller er gået bankerot
	 * @param p Spilleren der er gået bankerot
	 */
	public void bankruptcy(Player p){
		adapter.removeCar(p.getPosition()+1, p.getName()); // Fjerner spillerens bil fra spillepladen.
		int q = 0; 
		do{
			if (fields[q] instanceof Ownable){
				if (((Ownable) fields[q]).getOwner() == p){
					((Ownable) fields[q]).setOwner(null);
					adapter.removeOwner(q);
					if (fields[q] instanceof Property){
						((Property) fields[q]).setHouseCount(0);
						adapter.setHotels(q, false);
						adapter.setHouses(q, 0);
					}
				}
			}
			q++;
		}
		while (q < fields.length);
		updGuiFields();
	}

	/**
	 * Opretter samtlige felter 0-39 i Fields[]
	 * @param fieldPrices Priser på felterne (pris, huspris, pantsætningspris, bloknummer)
	 * @param fieldRents Priser for at lande for felterne (leje, 1hus, 2huse, 3huse, 4huse, hotel)
	 * @param titles Titler på felterne
	 * @param subtitles Subtitler på felterne
	 * @param descrip Beskrivelse af felterne
	 * @param luckTexts Tekster til prøv lykken kort
	 */
	public void createFields(int[][] fieldPrices, int[][] fieldRents, String[] titles, String[] subtitles, String[] descrip, String[] luckTexts){
		this.title = titles;
		this.desc = descrip;
		this.subtitle = subtitles;
		this.luckText = luckTexts;
		this.fieldPrice = fieldPrices;
		this.fieldRent = fieldRents;
		rent = new int[6];
		prices = new int[4];
		shipRent = new int[4];
		
		//Oprettelse af feltarray i rigtig rækkefølge
		fields = new Field[40];
		int n = 0;
		// Felt 1: Start felt
		fields[n] = new Refuge(title[n], subtitle[n], desc[n], fieldRent[n][0], n+1);
		n++;
		// Felt 2: Rødovrevej
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 3: Prøv lykken
		fields[n] = new Luck(title[n], subtitle[n], desc[n], n+1, luckText);
		n++;
		// Felt 4: Hvidovrevej
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 5: Skat
		fields[n] = new Tax(title[n], subtitle[n], desc[n], n+1, fieldPrices[n][0]);
		n++;
		// Felt 6: Redderi SFL
		for(int i = 0;i<4;i++){shipRent[i] = fieldRent[n][i];}
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Shipping(title[n], subtitle[n], desc[n], prices, n+1,shipRent, rent);
		n++;
		// Felt 7: Roskildevej
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 8: Prøv lykken
		fields[n] = new Luck(title[n], subtitle[n], desc[n], n+1, luckText);
		n++;
		// Felt 9: Valby Langgade
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 10: Allégade
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 11: Fængsel
		fields[n] = new Refuge(title[n], subtitle[n], desc[n], fieldRent[n][0], n+1);
		n++;
		// Felt 12: Frederiksberg Allé
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 13: Tuborg
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Brewery(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 14: Bülowsvej
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 15: Gl. Kongevej
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 16: Redderi DSB K/Å
		for(int i = 0;i<4;i++){shipRent[i] = fieldRent[n][i];}
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Shipping(title[n], subtitle[n], desc[n], prices, n+1,shipRent, rent);
		n++;
		// Felt 17: Bernstorffsvej
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 18: Prøv lykken
		fields[n] = new Luck(title[n], subtitle[n], desc[n], n+1, luckText);
		n++;
		// Felt 19: Hellerupvej
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 20: Strandvej
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 21: Parkering
		fields[n] = new Refuge(title[n], subtitle[n], desc[n], fieldRent[n][0], n+1);
		n++;
		// Felt 22: Trianglen
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 23: Prøv lykken
		fields[n] = new Luck(title[n], subtitle[n], desc[n], n+1, luckText);
		n++;
		// Felt 24: Østerbrogade
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 25: Grøningen
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 26: Redderi DFDS
		for(int i = 0;i<4;i++){shipRent[i] = fieldRent[n][i];}
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Shipping(title[n], subtitle[n], desc[n], prices, n+1,shipRent, rent);
		n++;
		// Felt 27: Bredgade
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 28: Kgs. Nytorv
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 29: Coca-Cola
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Brewery(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 30: Østergade
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 31: Gå i fængsel
		fields[n] = new Refuge(title[n], subtitle[n], desc[n], fieldRent[n][0], n+1);
		n++;
		// Felt 32: Amagertorv
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 33: Vimmelskaftet
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 34: Prøv lykken
		fields[n] = new Luck(title[n], subtitle[n], desc[n], n+1, luckText);
		n++;
		// Felt 35: Nygade
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 36: Redderi DSB H/K
		for(int i = 0;i<4;i++){shipRent[i] = fieldRent[n][i];}
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Shipping(title[n], subtitle[n], desc[n], prices, n+1,shipRent, rent);
		n++;
		// Felt 37: Prøv lykken
		fields[n] = new Luck(title[n], subtitle[n], desc[n], n+1, luckText);
		n++;
		// Felt 38: Frederiksbergade
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
		// Felt 39: Skat
		fields[n] = new Tax(title[n], subtitle[n], desc[n], n+1, fieldPrices[n][0]);
		n++;
		// Felt 40: Rådhuspladsen
		for(int i = 0;i<4;i++){prices[i] = fieldPrice[n][i];}
		for(int i = 0;i<6;i++){rent[i] = fieldRent[n][i];}
		fields[n] = new Property(title[n], subtitle[n], desc[n], n+1, prices, rent);
		n++;
	}

	public void snyd(Player player){
		// TESTKODE SKAL FJERNES
		for (int i=0; i<fields.length;i++){
			if (fields[i] instanceof Property){
				((Ownable) fields[i]).setOwner(player);
			}
		}
		updGuiFields();
		//landOnField(5, player, 7); // Land på et specifikt felt (første tal)
		//((Ownable) fields[6]).setOwner(null);
		// TESTKODE SLUT
	}

	public void sellGround(int i, Player player) {
		((Ownable) fields[i]).setOwner(player);
		updGuiFields();
	}
}